package zjc.DeviceManage.util;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.widget.Toast;

import java.util.prefs.Preferences;

/**
 * 作者：zxl on 2020/7/16 22:55
 * 邮箱：510252916@qq.com
 */
public class MyAppliacation extends Application {
    private static SharedPreferences pref;
    private static SharedPreferences.Editor editor;
    private static Context context;
    private static String user_id = "";

    public static Context getContext() {
        return context;
    }

    public static void setContext(Context context) {
        MyAppliacation.context = context;
    }

    public static String getUser_id() {
        return user_id;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        pref = PreferenceManager.getDefaultSharedPreferences(context);
        editor = pref.edit();
        editor.apply();
        user_id = pref.getString("user_id", "");

    }

    public static void setUser_id(String user_id) {
        MyAppliacation.user_id = user_id;
        editor.putString("user_id", user_id);
        editor.apply();
    }

    public static void subThreadToast(String message){
        Looper.prepare();
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        Looper.loop();
    }
}
